package main

import (
	"crypto/md5"
	"encoding/hex"
	"fmt"
	"net/url"
	"strconv"
	"time"

	"github.com/imroc/req"
)

func StrTime() string {
	return strconv.FormatInt(time.Now().Unix(), 10)
}
func B23(langurl string) string {
	type Data struct {
		Content string `json:"content"`
		Count   int64  `json:"count"`
	}
	type Share struct {
		Code    int64  `json:"code"`
		Message string `json:"message"`
		TTL     int64  `json:"ttl"`
		Data    Data   `json:"data"`
	}
	var body Share
	uri := "https://api.bilibili.com/x/share/click"
	data := "build=9333&buvid=abc1234abc1234abc1234abc1234abc1&platform=ios&share_channel=COPY&share_content=bishi&share_id=public.webview.0.0.pv&share_mode=3&share_title=bishi&oid=" + url.QueryEscape(langurl)
	req.C().R().SetContentType("application/x-www-form-urlencoded").SetBody(data).SetResult(&body).Post(uri)

	x := body.Data.Content
	if x == "" {
		return langurl
	}
	return x
}
func calcSign(text, secret string) string {
	md5Ctx := md5.New()
	md5Ctx.Write([]byte(text + secret))
	cipherStr := md5Ctx.Sum(nil)
	return hex.EncodeToString(cipherStr)
}

//Sign 1d8b6e7d45233436
func Sign(text string) string {
	return text + "&sign=" + calcSign(text, "560c52ccd288fed045859ed18bffd973")
}

//SignHD dfca71928277209b
func SignHD(text string) string {
	return text + "&sign=" + calcSign(text, "b5475a8825547a4fc26c7d518eaaa02e")
}

func printf(format string, a ...any) {
	print(fmt.Sprintf(format, a...))
}

func print(a ...any) {
	a = append([]any{time.Now().In(time.FixedZone("CST", 28800)).Format("\r[01-02 15:04:05]")}, a...)
	fmt.Println(a...)
}
